package level.editor.tool.tile;

import core.Constants;
import level.editor.command.Command;
import level.editor.command.RequiresModule;
import level.editor.mediator.Module;
import level.editor.state.StateModule;
import level.state.StateHandler;
import level.state.StateLayer;
import level.state.StateTileLayer;

public class RequestStateCommand extends Command implements RequiresModule
{
	private ToolTileLayer toolTileLayer;

	public RequestStateCommand(ToolTileLayer toolTileLayer)
	{
		super("StateModule");
		this.toolTileLayer = toolTileLayer;
	}

	@Override
	public void execute(Module m)
	{
		StateModule module = (StateModule) m;
		for (int i = -Constants.LAYER_MAX; i <= Constants.LAYER_MAX; i++)
		{
			StateLayer layer = StateHandler.getLayer(module.getState(), i);
			if (layer != null && layer instanceof StateTileLayer)
			{
				StateTileLayer tileLayer = (StateTileLayer) layer;
				toolTileLayer.addItem(tileLayer.getName());
				if (tileLayer.getZOrder() == 0)
				{
					toolTileLayer.setSelectedItem(tileLayer.getName());
				}
			}
		}
	}
}
